<?php
namespace app\business\controller;
use app\business\model\BusinessClassify;
use app\business\model\BusinessFormat;
use app\business\model\BusinessLogin;
use app\business\model\BusinessMenu;
use think\Controller;
use app\business\controller\Base;
use think\Session;

class Format extends Base
{
    //规格首页，显示出来所有的规格
    public function index($id)
    {
        $data = BusinessFormat::where('menu_id',$id)->select();
        $this->assign('id',$id);
        $this->assign('data',$data);
        return $this->fetch();
    }

    public function create($id)
    {
        $this->assign('id',$id);
        return $this->fetch();
    }

    public function store()
    {
        BusinessFormat::create($_POST);

        $id=$_POST['menu_id'];

        return redirect(url("/business/format/index/id/$id"));
    }

    public function delete($id,$data)
    {
        BusinessFormat::where('id',$id)->delete();

        return redirect(url("/business/format/index/id/$data"));
    }

    public function edit($id,$data)
    {
        //data是返回，id是正在修改
        $obj = BusinessFormat::where('id',$id)->find();

        $this->assign('id',$id);

        $this->assign('obj',$obj);

        $this->assign('data',$data);

        return $this->fetch();
    }

    public function update()
    {
        $data= $_POST['format_id'];

        unset($_POST['format_id']);

        $info = $_POST['menu_id'];

        unset($_POST['menu_id']);

        $userData = [
            'format_name' => $_POST['format_name'],
            'format_price' => $_POST['format_price']
        ];

        BusinessFormat::where('id',$info)->update($userData);

        return redirect(url("/business/format/index/id/$data"));
    }
}